package vip.idiy.anwei_android_iot.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import vip.idiy.anwei_android_iot.R;

/**
 * ClassName EditTextDialog
 * describe:
 * Created: 勇
 * Email:118085890@qq.com
 * Version: 1.0
 * Create in 10:24 2023/4/29
 */
public class EditTextDialog extends Dialog {
    private EditText editText;
    private TextView confirmButton;
    private TextView cancelButton;
    private OnTextEnteredListener listener;

    public EditTextDialog(Context context,String title) {
        super(context, R.style.custom_dialog);
        setContentView(R.layout.layout_edit_dialog);
        TextView layout_edit_dialog_title = findViewById(R.id.layout_edit_dialog_title);
        layout_edit_dialog_title.setText(title);
        editText = findViewById(R.id.layout_edit_dialog_edit_text);
        confirmButton = findViewById(R.id.layout_edit_dialog_sure);
        cancelButton = findViewById(R.id.layout_edit_dialog_cancel);
        confirmButton.setOnClickListener(v -> {
            String text = editText.getText().toString();
            if (listener != null) {
                listener.onTextEntered(text);
            }
            dismiss();
        });
        cancelButton.setOnClickListener(v -> dismiss());
    }

    public void setOnTextEnteredListener(OnTextEnteredListener listener) {
        this.listener = listener;
    }

    public interface OnTextEnteredListener {
        void onTextEntered(String text);
    }
}